

*******************************************************************************
****						Appendix Table G.3	- TRIP-LEVEL 
****		WILLINGNESS-TO-PAY ESTIMATES BY DECILE OF TRAVEL TIME SAVINGS
*******************************************************************************
use .\data\clean\I10W_laneuse_dataset_15nov14_wcensus, clear

capture drop if holiday==1
drop if dow==0 | dow==6
merge m:1 acct_no using ".\data\clean\\ZIP_accts", keep(1 3) nogen
sort zip_code
merge m:1 zip_code using ".\data\clean\censusdata", keep(1 3) nogen
sort acct_no
*WTP calculation
gen TT_dif_hr=dist/MLspeed-dist/ELspeed
gen WTP2=charged_toll/TT_dif_hr
*keep if WTP2>0&WTP2~=.
*keep if WTP2~=.
*keep if WTP2<0
drop if ELspeed==.
drop if TT_dif_hr==.
la var TT_dif_hr "Time in Hours"
keep if acct_type=="PRIVATE"&occupancy~="HOV-3"
keep if hour>4 & hour<9
drop if TT_dif_hr<0
g decile=.
g TT_dif_min=TT_dif_hr*60

forval i= 10(10)90{
	qui centile TT_dif_hr, c(`i')
	replace decile=`i'/100 if TT_dif_hr<=`r(c_1)' & decile==.
	}
replace decile=1 if decile==.
tabstat TT_dif_hr, by(decile)
replace decile=round(decile*10)
g count=1
egen freqpermo=sum(count), by(acct_no month)
g hrlywage=mean_inc/2040
//PANEL A
xtile decile_febmar = TT_dif_hr if WTP>0&WTP~=. & date<=td(31mar2013), nq(10)
xtile decile_jun = TT_dif_hr if WTP>0&WTP~=. & month==6, nq(10)
xtile decile_sep = TT_dif_hr if WTP>0&WTP~=. & month==9, nq(10)
matrix define A=J(10,8,.)
forval d=1/10{
	qui sum TT_dif_hr if decile==`d'
	local d1_`d'=round(`r(mean)',.01)
	qui sum TT_dif_min if decile==`d'
	local d2_`d'=round(`r(mean)',.01)
	qui sum charged_toll if decile==`d'
	local d3_`d'=round(`r(mean)',.01)
	qui sum WTP2 if decile==`d'
	local d4_`d'=round(`r(mean)',1)
	qui sum WTP2 if decile_febmar==`d' & month<4
	local d5_`d'=round(`r(mean)',1)
	qui sum WTP2 if decile_jun==`d' & month==6
	local d6_`d'=round(`r(mean)',1)
	qui sum WTP2 if decile_sep==`d' & month==9
	local d7_`d'=round(`r(mean)',1)
	matrix A[`d',1]=`d'
	matrix A[`d',2]=`d1_`d''
	matrix A[`d',3]=`d2_`d''
	matrix A[`d',4]=`d3_`d''
	matrix A[`d',5]=`d4_`d''
	matrix A[`d',6]=`d5_`d''
	matrix A[`d',7]=`d6_`d''
	matrix A[`d',8]=`d7_`d''
	}
qui sum TT_dif_hr
local d1_a=round(`r(mean)',.01)
qui sum TT_dif_min 
local d2_a=round(`r(mean)',.01)
qui sum charged_toll 
local d3_a=round(`r(mean)',.01)
qui sum WTP2 
local d4_a=round(`r(mean)',.1)
qui sum WTP2 if month<4
local d5_a=round(`r(mean)',.1)
qui sum WTP2 if  month==6
local d6_a=round(`r(mean)',.1)
qui sum WTP2 if  month==9
local d7_a=round(`r(mean)',.1)
matrix B=(.,`d1_a', `d2_a', `d3_a', `d4_a', `d5_a', `d6_a', `d7_a')
matrix C=(A\B)
matrix colnames C = Decile TimesavingsHrs TimesavingsMins TollPaid WTP_Full WTP_FebMar WTP_June WTP_Sept
putexcel set ".\results\appendix\AppendixFigsTabs.xlsx", modify sheet("Appendix Table G.3")
 putexcel A1=("I") B1=("II") C1=("III") D1=("IV") E1=("V") F1=("VI") G1=("VII") H1=("VIII")
putexcel B2:C2, merge
putexcel B2="Time Savings"
putexcel E2:H2, merge
putexcel E2="Average WTP per Hour"
putexcel A4=matrix(C)
putexcel A3=("Decile of Time Savings") B3=("in Hours") C3=("in Minutes") D3=("Average Toll Paid") E3=("Full Time Period") F3=("February & March") G3=("June") H3=("September") A14=("Average")
putexcel D4:D14, nformat(currency_d2_negbra)
putexcel E4:H14, nformat( currency_negbra )
*matrix list C
